<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <template v-if="isisDeleteShow">
        <span @click="$emit('clear-search-history')">全部删除</span>&nbsp;&nbsp;
        <span @click="isisDeleteShow = false">完成</span>
      </template>
      <van-icon v-else name="delete" @click="isisDeleteShow = true" />
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, i) in searchHistories"
      :key="i"
      @click="onHistoryClick(item, i)"
    >
      <van-icon v-if="isisDeleteShow" name="close" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isisDeleteShow: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onHistoryClick (item, i) {
      if (this.isisDeleteShow) {
        // 点击事件就是删除操作
        this.searchHistories.splice(i, 1)
        // this.$emit('clear-search-history', i)
      } else {
        // 点击事件就是搜索操作
        this.$emit('search', item)
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
